home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig05_12.jar / Ch05 / Fig05_12 / Fig05_12.cpp next >
C/C++ Source or Header  |  1997-10-14  |  401b  |  24 lines

  1. // Fig. 5.12: fig05_12.cpp
  2. // Attempting to modify data through a
  3. // non-constant pointer to constant data.
  4. #include <iostream.h>
  5.  
  6. void f( const int * );
  7.  
  8. int main()
  9. {
  10.    int y;
  11.  
  12.    f( &y );     // f attempts illegal modification
  13.  
  14.    return 0;
  15. }
  16.  
  17. // In f, xPtr is a pointer to an integer constant
  18. void f( const int *xPtr )
  19. {
  20.    *xPtr = 100;  // cannot modify a const object
  21. }
  22.  
  23.  
  24.